home *** CD-ROM | disk | FTP | other *** search
- Path: atglab.bls.com!Alun.Champion
- From: Alun.Champion@bridge.bst.bls.com (Alun Champion)
- Newsgroups: comp.lang.c
- Subject: Re: Newbie question: Is this code OK?
- Date: 18 Jan 1996 15:53:12 GMT
- Organization: Computer People Inc.
- Message-ID: <ALUN.CHAMPION.96Jan18105312@g7240065.bridge.bst.bls.com>
- References: <4di986$fk1@pegasus.interpac.net> <30FDDAC8.D79@e-tex.com>
- NNTP-Posting-Host: bstfirewall.bst.bls.com
- In-reply-to: smelly@e-tex.com's message of Wed, 17 Jan 1996 23:29:44 -0600
-
- In article <30FDDAC8.D79@e-tex.com> smelly@e-tex.com writes:
-
- : I am also new to C programming; however, I think I can make one
- : suggestion. Since your second for loop does all the work and you don't
- : need a body, you can write it like this.
-
- : for ( ; i<length, ((string[i]!='\n') &&
- : (string[i]!='\t') &&
- : (string[i]!=' ')); i++);
-
- Eeeek !
- I would serious suggest not putting the ';' on the end of the loop like the
- above because in the middle of code this can be hard to spot especially in
- conjunction with bad formatting.
-
- while (*s);
- *p++ = *s++;
- *p = '\0';
-
- I would suggest
-
- for (; *s; *p++ = *s++)
- ;
- *p = '\0';
-
- It's easier to spot.
-
- Regards
-
- -A
- --
- | A.Champion |
-